var carTeamStatisticsData = [];
var carTeamRecordData = [];
var totalPage = 0;
var totalCnt = 0;
var lastheaderNameEN = undefined;
var chargingKWHTotalList = [];
var chargingCountTotalList = [];
var totalChargingDTTMList = [];
var dataList = [];
var myChart = "";
var flagDate = undefined;

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	createTableHead("carTeamStatisticsThead", carTeamStatisticsTable, '');
	createTableHead("carTeamRecordThead", carTeamRecordTable, search);
	scrollTableSuspend("scrollBody", "carTeamRecordTable", "carTeamRecordTable1", "carTeamRecordThead", "scrollHeight");
	selectDate("monthDate",3 ,'', 3);
	selectDateTime("startDate");
	selectDateTime("endDate");
	changeMonth(0);
	setTimeout(hideLoading, 500);
});
function search(headerNameEN){
	if(lastheaderNameEN != headerNameEN){
		clearOrder(lastheaderNameEN);
		lastheaderNameEN = headerNameEN;
	}
	$ajax('searchCarTeamStatistics', 'carTeamStasticsSearch', searchCarTeamStatistics);
}
function searchCarTeamStatistics(data) {
	totalPage = data && data.totalPage || 0;
	totalCnt = data && data.totalCnt || 0;
	carTeamStatisticsData = data && data.carTeamStatisticsList || [];
	carTeamRecordData = data && data.carTeamRecordList || [];
	createTableBody("carTeamStatisticsTbody", carTeamStatisticsTable, carTeamStatisticsData, true, true);
	createTableBody("carTeamRecordTbody", carTeamRecordTable, carTeamRecordData);
	setTimeout(hideLoading, 500);
}
function showDay(index, date){
	$('.activeLi').removeClass("activeLi");
	$("#li"+ index).addClass("activeLi");
	var nowDate = stringToDate(date);
	nowDate.setDate(index);
	$("#startChargingTime").val(date2String(nowDate) + " 00:00:00");
	$("#endChargingTime").val(date2String(nowDate) + " 23:59:59");
	if($("#teamName").val() == ""){
		showMessge("请输入车队名称");
		return;
	}
	search();
}

function showForm(){
	if(document.getElementById("hideform").hidden){
		$("#hideform").attr("hidden", false);
	} else{
		$("#hideform").attr("hidden", true);
	}	
}

function changeEchart(){
	$("#histogram").empty();
	if(chargingStationNameList.length == 0){
		$("#contenter").attr("hidden",true);
		return;
	}
	$("#contenter").attr("hidden",false);
	myChart = echarts.init(document.getElementById('histogram'));
	var listName = $("#selectAllList").val();
	var theadName = undefined;
	var color = undefined;
	if(listName == "chargingKWHTotalList"){
		dataList = chargingKWHTotalList;
		theadName = "充电电量(KWH)";
		color = '#09be09';
	} else if(listName == "chargingCountTotalList"){
		dataList = chargingCountTotalList;
		theadName = "充电次数(次)";
		color = '#01b2ac';
	} else if(listName == "totalChargingDTTMList"){
		dataList = totalChargingDTTMList;
		theadName = "充电时长(秒)";
		color = '#fe902f';
	}
	var option = {
            tooltip: {
                trigger: 'axis'
            },
            xAxis: [
                {
                    type: 'category',
                    name: '充电站名称',
                    data: chargingStationNameList
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: theadName,
                    min: 0,
                    axisLabel: {
                        formatter: '{value} '
                    }
                }
            ],
            series: [
                {
                    name:theadName,
                    type:'bar',
                    itemStyle: {
                        normal : {
                            color: color,
                            label: {
                                show: true,
                                position: 'top',
                                formatter: '{c}'
                            }
                        }
                    },
                    data:dataList
                }
            ]
        };
    myChart.setOption(option);
}